/*
 * Created on 07-feb-2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.juanfrivaldes.cio2005.gestion;

import java.io.*;
import java.util.zip.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.juanfrivaldes.cio2005.domain.Ponencia;

/**
 * @author root
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class EnviarMailsAction extends GestionAction {

	private static Log log = LogFactory.getLog(EnviarMailsAction.class);
	/*
	 * (non-Javadoc)
	 * 
	 * @see com.juanfrivaldes.cio2005.web.BaseAction#protectedExecute(org.apache.struts.action.ActionMapping,
	 *      org.apache.struts.action.ActionForm,
	 *      javax.servlet.http.HttpServletRequest,
	 *      javax.servlet.http.HttpServletResponse)
	 */
	protected ActionForward protectedExecute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		EnviarMailsForm mailsForm = (EnviarMailsForm) form;
		
		String para=(String) request.getSession(false).getAttribute("para");
		log.trace("Asunto: "+mailsForm.getAsunto());
		log.trace("Cuerpo: "+mailsForm.getCuerpo());
		log.trace("Para: "+para);
		
		List destinatarios=null;
		if(request.getSession(false).getAttribute("para").equals("todos")){
			destinatarios=this.getCio2005().getUsuarios();
		}
		else{
			destinatarios=new ArrayList();
			destinatarios.add(this.getCio2005().getUsuario(para));
		}
		
		getCio2005().mailing(destinatarios,mailsForm.getAsunto(),mailsForm.getCuerpo());
		
		return mapping.findForward("success");
	}

}
